<template>
    <div class="icons">
        <swiper>
            <swiper-slide v-for="(page,index) of pages" :key="index">
                <div class="icon" v-for="item of page" :key="item.id">
                    <div class="img-style">
                        <img class="img-icon" :src="item.imgUrl" alt="" >
                    </div>
                    <p>{{item.desc}}</p>
                </div>
            </swiper-slide>
        </swiper>
    </div>
</template>
<script>
export default {
  name: "HomeIcons",
  props: {
    list: Array
  },
  computed: {
    pages() {
      const pages = [];
      this.list.forEach((item, index) => {
        const page = Math.floor(index / 8);
        if (!pages[page]) {
          pages[page] = [];
        }
        pages[page].push(item);
      });
      return pages;
    }
  }
};
</script>
<style lang="stylus" scoped>
.icons {
    overflow: hidden;
    height: 0;
    padding-bottom: 50%;
    background: #f6f6f6;
}

.icon {
    float: left;
    width: 25%;
    height: 0;
    overflow: hidden;
    padding-bottom: 25%;
}

.icon {
    text-align: center;
}

.icon p {
    word-break: keep-all;
    white-space: nowrap;
    overflow: hidden;
    padding-top: 0.1rem;
    text-overflow: ellipsis;
}

.img-style {
    margin-top: 0.2rem;
}

.img-icon {
    max-width: 60%;
}
</style>